package com.situ.mymall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.mymall.mapper.OrderItemMapper;
import com.situ.mymall.pojo.entity.OrderItem;
import com.situ.mymall.pojo.query.OrderItemQuery;
import com.situ.mymall.service.IOrderItemService;
import com.situ.mymall.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderItemServiceImpl implements IOrderItemService {

    @Autowired
    private OrderItemMapper orderItemMapper;


    @Override
    public PageResult list(OrderItemQuery orderItemQuery) {
        PageHelper.startPage(orderItemQuery.getPage(), orderItemQuery.getLimit());
        List<OrderItem> list = orderItemMapper.list(orderItemQuery);
        PageInfo pageInfo = new PageInfo(list);
        int totalCount = (int) pageInfo.getTotal();

        return PageResult.ok(totalCount,list);
    }

    @Override
    public OrderItem selectById(Integer id) {
        return orderItemMapper.selectByPrimaryKey(id);
    }

    @Override
    public void add(OrderItem orderItem) {
        orderItemMapper.insertSelective(orderItem);
    }

    @Override
    public void deleteById(Integer id) {

        orderItemMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        orderItemMapper.deleteAll(ids);
    }

    @Override
    public void update(OrderItem orderItem) {
        orderItemMapper.updateByPrimaryKeySelective(orderItem);
    }


}
